/*
package com.spsy.search.repository;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.function.ObjBoolConsumer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.spsy.search.entity.SpsyProject;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

*/
/**
 * 对象具体化了，
 * @author: liuzhiping
 * @date: 2024/11/29 12:00
 **//*

@Component
public class SpsyProjectRepositroy implements EntityRepositoryInterface<String,String, SpsyProject>{

    @Autowired
    private EntityRepositoryWrapper entityRepositoryWrapper;
    @Override
    public String add(String name, String id, SpsyProject spsyProject) {

        //跟具体对象绑定，到具体的repository
        IndexRequest indexRequest = new IndexRequest(name);
        indexRequest.id(id);
        indexRequest.source(new ObjectMapper().convertValue(spsyProject, Map.class));

        try {
            return this.entityRepositoryWrapper.add(indexRequest);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    public String del(String name, String id) {

        DeleteRequest request = new DeleteRequest(name);
        request.id(id);
        try {
            return this.entityRepositoryWrapper.del(request);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public SpsyProject getById(String name, String id) {

        GetRequest request = new GetRequest(name);
        request.id(id);
        try {
            Map<String,Object> map = this.entityRepositoryWrapper.get(request);

            System.out.println("获取数据 map="+ JSON.toJSONString(map));

            SpsyProject spsyProject = new ObjectMapper().readValue(JSON.toJSONString(map),SpsyProject.class);

            System.out.println("获取数据 spsyProject="+ JSON.toJSONString(spsyProject));

            return spsyProject;

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
*/
